package entities;

import interfaze.SpaceInvadersGamingPanel;

import java.awt.Image;

import javax.swing.ImageIcon;

import logic.Utilities;

@SuppressWarnings("serial")
public class EnemyShot extends MovableEntity {

	ImageIcon icon;
	
	/**
	 * creates a Enemy Shot class movable entity with the provided coordinates, speed and panel
	 * @param x
	 * @param y coordinates
	 * @param dx
	 * @param dy speed
	 * @param p panel to which the enemy shot belongs
	 */
	public EnemyShot(int x, int y, int dx, int dy, SpaceInvadersGamingPanel p) {
		super(x, y, dx, dy);
		this.p=p;
		Image image = Utilities.loadImage("res/ENEMYSHOT.png");
		icon = new ImageIcon(image);
		this.setIcon(icon);
		this.width = image.getWidth(null);
		this.height = image.getHeight(null);
		this.setBounds((int)this.x, (int)this.y, this.width, this.height);
		lastUpdate=System.currentTimeMillis();
	}
	/**
	 * checks whether this shot has collided with the player, in which case an impact is added to the Defender, if the number of impacts is greater than the numer of lives, the player loses
	 * @param d a Defender class object, the player
	 */
	public void impacts(Defender d){
		if (d.getBounds().intersects(this.getBounds())){
			d.hits++;
			this.setVisible(false);
		}
	}
}
